#include <stdio.h>
#include <omp.h>
//编译指令
//gcc -std=c99 -fopenmp 7Atomic.c -o cmake-build/7Atomic && export OMP_NUM_THREADS=512 && time ./cmake-build/7Atomic
void test1(void)
{
    int n=2015,ic=0;
    #pragma omp parallel for shared(ic,n) default(none)
    for(int i=0;i<n;i++)
    {
        #pragma omp atomic
        ic+=1;
        #pragma omp atomic
        ic=2-ic-ic;
    }
    printf("test1 Counter=%d\n",ic);
}
void test2(void)
{
    int n=2015,ic=0;
    #pragma omp parallel for shared(ic,n) default(none)
    for(int i=0;i<n;i++)
    {
        ic+=1;
    }
    printf("test2 Counter=%d\n",ic);
}
int main()
{
    test1();
    test2();
    return 0;
}
